var mainApp={

	chooseNood:1,
	//绑定dowm(多项选择)
	bindChtml:function(){
		var str="";
            str+="<span class='contactAction' style='left: 157px; top: 282px; position: fixed;'>",
            str+="<span permission='departmentEdit' class='icon_span'><a id='addBtn_'>新增 </a></span>",
            str+="<span permission='departmentEdit' class='icon_span'><a id='addBatchBtn_'>添加成员</a></span>",
            str+="<span permission='contactDel' class='icon_span'><a id='delBatchBtn_'>移除成员</a></span>",
            str+="<span permission='departmentEdit' class='icon_span'><a id='editBtn_'>编辑</a></span>",
            str+="<span permission='departmentDel' class='icon_span'><a id='removeBtn_'>删除</a></span>",
            str+="</span>";
        return str;
	},

	//绑定dowm（只有新增的）
	bindPhtml:function(){
		var str="<span class='contactAction' style='width: 40px; right: -50px; position: absolute;'>";
            str+="<span class='icon_span'><a id='addBtn_'>新增</a></span>",
            str+="</span>";
        return str;
	},

	//绑定dowm(选择部门)
	bindCheckNode:function(arr){
		var str="";
    		str="<li><span>"+arr+"</span><i onclick='delDep(this)'></i></li>";
    		$("#nodeNames").append(str);
	},

	//点击节点获取子节点信息
	 moveNode:function(allNodes){
	 	// console.log(treeNode)
		for(var i=0;i<allNodes.length;i++){
                
	        $("#"+allNodes[i].tId+"_a").hover(function(){
	            if($(this).parent().parent().hasClass('ztree')){

	                $(this).append(mainApp.bindPhtml());

	                //新增
	                mainApp.treeAdd($(this));
	                
	            }else{
	                $(this).append(mainApp.bindChtml());

	                var left=$(this).offset().left+$(this).width();
	                var top=$(this).offset().top;
	                var scrollTop=$(document).scrollTop();
	                $(this).find(".contactAction").css({
	                    position:"fixed",
	                    left:left,
	                    top:top-scrollTop,
	                    marginLeft:"10px"
	                });

	                //新增
	                mainApp.treeAdd($(this));
	                //添加成员
	                mainApp.treeAddMenber($(this));
	                //移除成员
	                mainApp.treeDelMenber($(this));
	                //编辑成员
	                mainApp.treeEditMenber($(this));
	                //删除部门
	                mainApp.treeRemoveMenber($(this));
	            }  
	        },function(){
	            if($(this).parent().parent().hasClass('ztree')){
	                $(this).find(".contactAction").remove();
	            }else{
	                $(this).find(".contactAction").remove();
	            }
	        });
	    }
	},

	//点击树的新增
	treeAdd:function(tId){
		tId.find("#addBtn_").click(function(){
			//console.log(tId.parent().prop("id"))
			/*var ctid=tId.parent().prop("id");
			var treeObj = $.fn.zTree.getZTreeObj("myContactTree");

			var node=treeObj.getNodeByTId(ctid);
			console.log(node);

			var nid=tId.parent().prop("id");
			var zTree = $.fn.zTree.getZTreeObj("myContactTree");

			var newNode={name:"newNode"};
			newNode =zTree.addNodes(node,newNode);*/
			
			/*$("#treeNodeid").val(nid);
			console.log($("#treeNodeid").val());*/

			$("#personFrame").prop("src","addTag.html");
			return false;
		});
	},

	//添加成员
	treeAddMenber:function(tId){
		tId.find("#addBatchBtn_").click(function(){
			window.open("addMenber.html","newWin","height=700, width=1000, left=300, top=200");
			return false;
		});
	},

	//移除成员
	treeDelMenber:function(tId){
		tId.find("#delBatchBtn_").click(function(){
			window.open("addMenber.html","newWin","height=700, width=1000, left=300, top=200");
			return false;
		});	
	},

	//编辑成员
	treeEditMenber:function(tId){
		tId.find("#editBtn_").click(function(){
			$("#personFrame").prop("src","addTag.html");
			return false;
		});
	},

	//删除部门
	treeRemoveMenber:function(tId){
		tId.find("#removeBtn_").click(function(){
			$("#overlayDiv").css({display:"block"});
			$("#delOrgConfirmBox").css({display:"block"});
			return false;
		});
	},

	//判断是否需要编辑
	editDepartment:function(treeNode){
		if(!$("#"+treeNode.tId+"_a").parent().parent().hasClass("ztree")){
            $("#personFrame").contents().find("#editBtn").css({
                display:"inline-block",
                paddingLeft:"0",
                marginRight:"0"
             }).siblings('a').css({
                paddingLeft:"0",
                marginLeft:"5px"
             });
         }else{
            $("#personFrame").contents().find("#editBtn").css({
                display:"none",
             }).siblings('a').css({
                paddingLeft:"30px"
             });
         }
	}



}